﻿using HlELock.Domain.Entities;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace HlELock.Core.ViewModels
{
    public class SelectRoomUserControlViewModel : BindableBase, IDialogAware
    {
        public SelectRoomUserControlViewModel()
        {

        }
        private DelegateCommand<Room> _doubleClickCommand;
        public DelegateCommand<Room> DoubleClickCommand =>
            _doubleClickCommand ?? (_doubleClickCommand = new DelegateCommand<Room>(ExecuteDoubleClickCommand));

        void ExecuteDoubleClickCommand(Room obj)
        {
            var args = new DialogParameters
            {
                { "args", obj }
            };
            RequestClose?.Invoke(new DialogResult(ButtonResult.OK, args));
        }
        private ObservableCollection<Room> _rooms;
        public ObservableCollection<Room> Rooms
        {
            get { return _rooms; }
            set { SetProperty(ref _rooms, value); }
        }
        string IDialogAware.Title => AppHelper.GetResourceString("XuanZeFangJian");

        public event Action<IDialogResult> RequestClose;

        bool IDialogAware.CanCloseDialog()
            => true;

        void IDialogAware.OnDialogClosed()
        {

        }

        void IDialogAware.OnDialogOpened(IDialogParameters parameters)
        {
            Rooms = parameters.GetValue<List<Room>>("args").ToObservableCollection();
        }
    }

}
